package com.lingo.ffmpegdemo.ffmpegutils;

import java.io.*;
import java.text.SimpleDateFormat;

/**
 * @Description: TODO
 * @Author watson
 * @Date 2022/7/18 17:58
 * @Version 1.0
 */
public class BreakFile {

    public static void ReadData() throws Exception {
        try {
            FileReader read = new FileReader("D:/data.txt");
            BufferedReader br = new BufferedReader(read);
            String row;
            int rownum = 1;
            FileWriter fw1 = new FileWriter("/text1.txt");
            FileWriter fw2 = new FileWriter("/text2.txt");
            FileWriter fw3 = new FileWriter("/text3.txt");
            FileWriter fw4 = new FileWriter("/text4.txt");

            while ((row = br.readLine()) != null) {
                if (rownum % 4 == 1) {
                    fw1.append(row + "\r\n");
                } else if (rownum % 4 == 2) {
                    fw2.append(row + "\r\n");
                } else if (rownum % 4 == 3) {
                    fw3.append(row + "\r\n");
                } else if (rownum % 4 == 0) {
                    fw4.append(row + "\r\n");
                }
                rownum++;
            }
            fw1.close();
            fw2.close();
            fw3.close();
            fw4.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**
     * 统计文件行数
     */
    public static void beforeBreakFile() {

        try {
            FileReader read = new FileReader("D:\\天翼云盘下载\\nohup.out");
            BufferedReader br = new BufferedReader(read);
            String row;
            int rownum = 1;
            while ((row = br.readLine()) != null) {
                rownum++;
            }
            System.out.println("rownum=" + rownum);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * 得到的总行数是，除以n,得到拆分后文件的行数
     * 文件拆分
     */
    public static void breakFile() {
        try {
            FileReader read = new FileReader("D:\\天翼云盘下载\\nohup.out");
            BufferedReader br = new BufferedReader(read);
            String row;
            int rownum = 1;
            int fileNo = 1;
            FileWriter fw = new FileWriter("D:\\天翼云盘下载\\" + fileNo + ".txt");
            while ((row = br.readLine()) != null) {
                rownum++;
                fw.append(row + "\r\n");
                if ((rownum / 1700000) > (fileNo - 1)) {
                    fw.close();
                    fileNo++;
                    fw = new FileWriter("D:\\天翼云盘下载\\" + fileNo + ".txt");
                }
            }
            fw.close();
            System.out.println("rownum=" + rownum + ";fileNo=" + fileNo);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = simpleDateFormat.format(1657794454000L);
        System.out.println(format);
    }
}
